@extends("admin.base")
@section("content")
        <section class="content"> 
          <div class="row">
            <div class="col-md-12">
              <div class="box">
                <div class="box-header with-border">
                  <h3 class="box-title"><i class="fa fa-th"></i> 分类列表</h3> &nbsp;&nbsp;&nbsp;&nbsp;&nbsp;
                    <button class="btn btn-primary"  onclick="loadAdd()">添加类型信息</button>
                </div><!-- /.box-header -->
                <div class="box-body">
                  <table class="table table-bordered">
                    <tr>
                      <th style="width:60px">类别ID</th>
                      <th>类别名称</th>
                      <th>父类PID</th>
                      <th>路径PATH</th>
                      <th>上架与否状态显示</th>
                      <th style="width: 100px">操作</th>
                    </tr>
					       @foreach($list as $v)
                    <tr>
                      <td>{{$v->id}}</td>
                      <td>{{$v->name}}</td>
                      <td>{{$v->pid}}</td>
                      <td>{{$v->path}}</td>
                      <td>{{$v->status}}</td>
                      <td>
                        <button id="mydel" class="btn btn-xs btn-danger" onclick="doDel({{$v->id}})">删除</button> 

                    <a href="{{url('admin/cate')}}/{{$v->id}}"><button class="btn btn-xs btn-primary">编辑</button></a></td>
                        
                    </tr>
                   @endforeach
                  </table>
                </div><!-- /.box-body -->
                <div class="box-footer clearfix" >
                  <ul class="pagination pagination-sm no-margin pull-right">
                     <li><a href="#">&laquo;</a></li>
                     <li><a href="#">1</a></li>
                     <li><a href="#">2</a></li>
                     <li><a href="#">3</a></li>
                     <li><a href="#">&raquo;</a></li>                     
                   </ul>       
                </div>
              </div><!-- /.box -->
            </div><!-- /.col -->           
          </div><!-- /.row -->        
        </section><!-- /.content -->
        <form action="" style="display:none;" id="mydeleteform" method="post">
            <input type="hidden" name="_token" value="<?php echo csrf_token(); ?>">
            <input type="hidden" name="_method" value="DELETE">
        </form>
      </div><!-- /.content-wrapper -->

      

@endsection

@section("myscript")

    <div class="modal fade" id="exampleModal" tabindex="-1" role="dialog" aria-labelledby="exampleModalLabel">
        <div class="modal-dialog" role="document">
        <div class="modal-content">
          <div class="modal-header">
            <button type="button" class="close" data-dismiss="modal" aria-label="Close"><span aria-hidden="true">&times;</span></button>
            <h4 class="modal-title" id="exampleModalLabel">New message</h4>
          </div>
          <div class="modal-body">

           <!-- 此处填充 -->

          </div>
          <div class="modal-footer">
            <button type="button" class="btn btn-default" data-dismiss="modal">关闭</button>
            <button type="button" onclick="saveType()" class="btn btn-primary">保存</button>
          </div>
        </div>
      </div>
    </div>

       <!-- 执行删除 -->
      <script type="text/javascript">
            function doDel(id){
                if(confirm('确定要删除吗？')){
                    $("#mydeleteform").attr("action","{{url('admin/cate')}}/"+id).submit(); 
                }
           
                /* Modal.confirm({msg:'确认删除此类别？'}).on(function (e){
                if(e){
                    var form = document.getElementById("mydeleteform");
                    form.action = "{{URL('/admin/cate')}}/"+id;
                    form.submit(); 
                }
            });     */   
            }



         // 加载添加表单
         function loadAdd(){
            $("#exampleModalLabel").html("添加商品类别");
            $("#exampleModal").modal("show");     
            $.ajax({
                url:"{{URL('admin/cate/create')}}",
                type:"get",
                dataType:"html",
                async:true,
                success:function(data){
                  $("#exampleModal .modal-body").html(data);   
                },
             }); 
        }
       //保存添加信息
        function saveType(){
            $("#myform").submit();
          /* alert("ok");*/
            /*$.ajax({
                url:"{{url('admin/cate')}}",
                type:"post",
                dataType:"html",
                data:$("#myform").serialize() ,
                async:true,
                success:function(data){
                    $('#exampleModal').modal('hide');
                    Modal.alert({msg:data,title: ' 信息提示',btnok: '确定',btncl:'取消'});
                    $("div.content-wrapper").html(data);
                },
             });*/
           }
      </script>
@endsection